$(function () {
    $.initPage(sourcingRequisitionDetail.load.start);
});

var sourcingRequisitionDetail = new BaseFrame();

sourcingRequisitionDetail.addBlock(
    'specInformation',
    'additionalInformation',
    'utbFieldInformation',
    'statementInformation',
    'operationInformation'
);

sourcingRequisitionDetail.load.addStart(function () {
    $.getFormDetail()
        .then(function (data) {
            _data = $.extend({}, data);
            $('#form-detail').data('detail', $.extend({}, _data.formDetail ? _data.formDetail.formDetail : {}));
            return $.pageStart(_eLancoSettings);
        })
        .then(function () {
            if ($.isEmpty(_data.formDetail)) {
                $.alert(_enumMessage.noRecord, $.exitForm);
            } else {
                sourcingRequisitionDetail.load.runTask();
                sourcingRequisitionDetail.event.runTask();
                sourcingRequisitionDetail.verify.status();
            };
        });

});

sourcingRequisitionDetail.load.addBind('createTitle', function () {
    var currentPage = $.getCurrentPage(_eLancoSettings.pageList);
    $('title').text(currentPage.title);
});

sourcingRequisitionDetail.load.addBind('createNav', function () {
    var navList = $.getUserAuthorityList(_user.roleList, _eLancoSettings.authorityList, _eLancoSettings.pageList);
    $('#logout').on('click', $.logoff);
    $('#block-nav').createNavList(navList).removeClass('dn');
});

sourcingRequisitionDetail.load.specInformation.addBind('createspecInformation', function () {
    var domStorage = $('#form-detail');
    var formDetail = domStorage.data('detail');
    //测试用
    _data.teamList = [{ id: 1, name: 'UTB' }, { id: 2, name: 'MICE' }];
    $('#field-detail-legalEntity').createSelect(domStorage, 'detail.legalEntity', $.getKeyValueList('id', 'name', _data.teamList), {
        required: true,
    });
    $('#field-detail-activeName').createString(domStorage, 'detail.activityName', {
        required: true,
    });
    $('#field-detail-budget').createDecimal(domStorage, 'item.budget', {
        required: true,
    });
    $('#field-detail-budget').createUnit(null, 'RMB');
    $('#field-detail-department').createSelect(domStorage, 'detail.department', $.getKeyValueList('id', 'name', _data.teamList), {
        required: true,
    });
    $('#field-detail-costCenter').createString(domStorage, 'detail.costCenter', {
        required: true,
    });
    $('#field-detail-atsApprover').createUserStandard(domStorage, 'detail.atsApprover', { displayInTextBox: true });
    if ($.isEmpty($.getParam('id'))) {
        formDetail.opOwner = _user;
        $('#field-detail-opOwner').createUserStandard(domStorage, 'detail.opOwner', { displayInTextBox: true });
        $('#field-detail-opOwner').trigger('selectUserCallback', _user);
        formDetail.email = _user.email;
    } else {
        $('#field-detail-opOwner').createUserStandard(domStorage, 'detail.opOwner', { displayInTextBox: true });
    }
    // $('#field-detail-opOwner').createUserStandard(domStorage, 'detail.opOwner', { displayInTextBox: true });
    $('#field-detail-email').createString(domStorage, 'detail.email', {
        required: true,
    });
    $('#field-detail-phone').createString(domStorage, 'detail.phone');
    $('#block-basic-information').removeClass('dn');
});

sourcingRequisitionDetail.load.specInformation.addBind('createSpecificationInformation', function () {
    var domStorage = $('#form-detail');
    var formDetail = domStorage.data('detail');
    // var templatepecDesc = $('#template-spec-desc').html();
    //测试用
    _data.teamList = [
        { id: 1, name: '企业硬件 - Enterprise Hardware' },
        { id: 2, name: '翻译服务 - Translation' },
        { id: 1, name: '全球健康研究 - Global Health Outcome' },
        { id: 2, name: 'IT基础设施服务 - IT Managed Infrastructure Services' },
        { id: 1, name: '企业硬件 - Enterprise Hardware' },
        { id: 2, name: '培训 - Training' },
        { id: 1, name: '市场研究 - Market Research' },
        { id: 2, name: '创意&广告 - Creative & Advertising' },
        { id: 2, name: '网络营销 - Digital Marketing' },
        { id: 2, name: '公共关系 - Public Relations' },
        { id: 2, name: '打印材料 - Printing Material' },
        { id: 2, name: '销售促销项目 - Promotional Items' },
        { id: 2, name: '广告空间 - Advertising Space' },
    ];
    $('#field-utb-spec-category').createSelect(domStorage, 'detail.utbSpecCategory', $.getKeyValueList('id', 'name', _data.teamList), {
        required: true,
    });
    var specInformationList = domStorage.data('detail').specificationInformationList;
    if ($.isEmpty(specInformationList))
        sourcingRequisitionDetail.load.specInformation.createSpecificationInformationItem();
    else
        for (var i = 0; i < specInformationList.length; i++)
            sourcingRequisitionDetail.load.specInformation.createSpecificationInformationItem(specInformationList[i]);
    $('#field-utb-specItemList .btn:eq(0)').hide();
});

sourcingRequisitionDetail.load.specInformation.addEvent('createSpecificationInformationItem', function (itemData) {
    itemData = itemData || {};
    var template = $('#template-field-utb-spec-item').html();
    $('#field-utb-specItemList tbody').createTemplate(template);
    var itemDomStorage = $('#field-utb-specItemList tbody tr:last');
    itemDomStorage.data('item', $.extend({}, itemData));
    $('#field-utb-specItemList tbody tr:last td:eq(0)').createString(itemDomStorage, 'item.utbSpecDesc', {
        required: true,
    });
    $('#field-utb-specItemList tbody tr:last td:eq(3)').createString(itemDomStorage, 'item.utbSpecRemark', {
        placeholder: '比如是否有推荐供应商，如有请添加。'
    });
    $('#field-utb-specItemList tbody tr:last td:eq(1)').createInteger(itemDomStorage, 'item.utbSpecQty');
    _datepicker.startDate = new Date();
    _datepicker.startDate.addDays(10);
    $('#field-utb-specItemList tbody tr:last td:eq(2)').createDatepicker(itemDomStorage, 'item.utbSpecDate', {
        required: true,
    });
});

sourcingRequisitionDetail.load.additionalInformation.addBind('createAdditionalInformation', function () {
    var domStorage = $('#form-detail');
    var formDetail = domStorage.data('detail');
    $('#field-additional-remark').createString(domStorage, 'detail.additionalRemark');
    $('#field-additional-attachment').createStandardAttachment(domStorage, 'detail.additionalAttenchment');
    $('#block-additional').removeClass('dn');
});

sourcingRequisitionDetail.load.utbFieldInformation.addBind('createUTBFieldInformation', function () {
    var domStorage = $('#form-detail');
    var formDetail = domStorage.data('detail');
    //测试用
    _data.teamList = [{ id: 1, name: 'UTB' }, { id: 2, name: 'MICE' }];
    _data.biddingList = [{ key: true, value: 'Yes' }, { key: false, value: 'No' }];
    _data.biddingTypeList = [{ key: 1, value: 'Bidding analysis' }, { key: 2, value: 'Bidding waiver' }, { key: 3, value: 'Dual saving' }];
    _data.savingMethodList = [{ key: 1, value: 'Cost improvement' }, { key: 2, value: 'Cost avoidance' }, { key: 3, value: 'Mixed' }];
    _data.procurementTypeList = [{ key: 1, value: 'Sourcing Project' }, { key: 2, value: 'Transactional Project' }];
    $('#field-utb-contract-amount').createDecimal(domStorage, 'detail.utbContractAmount', {
        required: true,
    });
    $('#field-utb-contract-amount').createUnit(null, 'RMB');
    $('#field-utb-bidding').createSelect(domStorage, 'detail.utbBidding', $.getKeyValueList('key', 'value', _data.biddingList), {
        required: true,
    });
    $('#field-utb-bidding-type').createSelect(domStorage, 'detail.utbBiddingType', $.getKeyValueList('key', 'value', _data.biddingTypeList), {
        required: true,
    });
    $('#field-utb-saving-method').createSelect(domStorage, 'detail.utbSavingMethod', $.getKeyValueList('id', 'name', _data.savingMethodList), {
        required: true,
    });
    $('#field-utb-cost-avoidance').createDecimal(domStorage, 'detail.utbCostAvoidance', {
        required: true,
    });
    $('#field-utb-cost-avoidance').createUnit(null, 'RMB');
    $('#field-utb-cost-saving').createDecimal(domStorage, 'detail.utbCostSaving', {
        required: true,
    });
    $('#field-utb-cost-saving').createUnit(null, 'RMB');
    $('#field-utb-late-involvment').createSelect(domStorage, 'detail.utbLateInvolvment', $.getKeyValueList('key', 'value', _data.biddingList), {
        required: true,
    });
    $('#field-utb-lowest-price-selected').createSelect(domStorage, 'detail.utbLowestPriceSelected', $.getKeyValueList('key', 'value', _data.biddingList), {
        required: true,
    });
    $('#field-utb-procurement-type').createSelect(domStorage, 'detail.utbProcurementType', $.getKeyValueList('key', 'value', _data.procurementTypeList), {
        required: true,
    });
    // $('#block-utb-field').removeClass('dn');
});

sourcingRequisitionDetail.load.statementInformation.addBind('createStatementInformation', function () {
    var domStorage = $('#form-detail');
    var formDetail = domStorage.data('detail');
    //测试用
    var complianceAudit = [{ name: 'complianceAuditTrue', value: '是' }, { name: 'complianceAuditFalse', value: '否' }];
    var qualityAudit = [{ name: 'qualityAuditTrue', value: '是' }, { name: 'qualityAuditFalse', value: '否' }];
    $('#field-statement-compliance').createIconRadio(domStorage, 'detail.complianceAudit', $.getKeyValueList('name', 'value', complianceAudit), {
        required: true,
    });
    $('#field-statement-quality').createIconRadio(domStorage, 'detail.qualityAudit', $.getKeyValueList('name', 'value', qualityAudit), {
        required: true,
    });
    $('#block-statement').removeClass('dn');
});

sourcingRequisitionDetail.form.addEvent('exitForm', $.exitForm);

sourcingRequisitionDetail.form.addEvent('submitForm', function () {
    var id = $.isEmpty($.getParam('id')) ? 0 : $.getParam('id');
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = sourcingRequisitionDetail.save.formDetail();
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail
    });
    if($.isEmpty(_data.formDetail.historyId)) {
        params.reSubmit = false;
    }else {
        params.reSubmit = true;
    }
    $.post(_apiPath + '/eLancos/FormDetails/' + id + '/Submit', params)
        .then(function (data) {
            $.alert(_enumMessage.submitSuccess, sourcingRequisitionDetail.form.exitForm);
        });
});

sourcingRequisitionDetail.form.addEvent('completeForm', function () {

});

//form module
sourcingRequisitionDetail.form.addEvent('saveForm', function () {
    var id = $.isEmpty($.getParam('id')) ? 0 : $.getParam('id');
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = sourcingRequisitionDetail.save.formDetail();
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail
    });
    $.post(_apiPath + '/eLancos/FormDetails/' + id + '/Save', params)
        .then(function (data) {
            $.alert(_enumMessage.saveSuccess, sourcingRequisitionDetail.form.exitForm);
        });
});

sourcingRequisitionDetail.form.addEvent('kickoffForm', function () {
    var id = $.isEmpty($.getParam('id')) ? 0 : $.getParam('id');
    var formId = $.isEmpty($.getParam('formId')) ? 0 : $.getParam('formId');
    var formDetail = sourcingRequisitionDetail.save.formDetail();
    var params = $.getFormDetailParams(_data.formDetail, {
        formId: formId,
        formDetail: formDetail
    });
    $.post(_apiPath + '/eLancos/FormDetails/' + id + '/Approval', params)
        .then(function (data) {
            $.alert(_enumMessage.approveSuccess, sourcingRequisitionDetail.form.exitForm);
        });
});

sourcingRequisitionDetail.event.operationInformation.addBind('operation', function () {
    var domStorage = $('#form-detail');
    var data = _data.formDetail;
    var evTimeStamp = 0;
    $('#block-operation-information').on('click', '.btn[exit]', sourcingRequisitionDetail.form.exitForm);
    $('#block-operation-information').on('click', '.btn[submit]', function () {
        if (!sourcingRequisitionDetail.verify.submitForm()) return false;
        sourcingRequisitionDetail.form.submitForm();
    });
    $('#block-operation-information').on('click', '.btn[edit]', function () {
        var origin = window.location.origin;
        var url = `${origin}/request/sourcingRequisitionDetail?model=detail&formId=3&id=${data.id}&backId=2&action=edit`;
        window.location.href = url;
    });
    // $('#block-operation-information').on('click', '.btn[complete]', function () {
    //     if (!sourcingRequisitionDetail.verify.completeForm()) return false;
    //     sourcingRequisitionDetail.form.completeForm();
    // })
    $('#block-operation-information').on('click', '.btn[kickoff]', function () {
        if (!sourcingRequisitionDetail.verify.kickoffForm()) return false;
        sourcingRequisitionDetail.form.kickoffForm();
    });
    $('#block-operation-information').on('click', '.btn[save]', sourcingRequisitionDetail.form.saveForm)

    $('#block-operation-information').on('click', '.btn[complete]', function () {
        if (!sourcingRequisitionDetail.verify.completeForm()) return false;
        sourcingRequisitionDetail.form.kickoffForm();
    })

});

sourcingRequisitionDetail.event.specInformation.addBind('specificationInformationOperation', function () {
    var formDetail = $.extend({}, $('#form-detail').data('detail'));
    $('#field-utb-specItemList').on('click', '.btn[addNew]', function () {
        if ($('#field-utb-specItemList tr[data]').length >= 10) return $.alert(sourcingRequisitionDetail.message.specInformation.specificationInformationListLimit);
        sourcingRequisitionDetail.load.specInformation.createSpecificationInformationItem();
    });

    $('#field-utb-specItemList').on('click', '.btn[delete]', function () {
        $(this).parents('tr[data]').remove();
    });
    $('#field-utb-bidding').on('changeCallback', function (event, user) {
        if (user == 'true') {
            console.log(user);
            $('#field-utb-bidding-type').enabledForm();
        } else {
            console.log(user);
            $('#field-utb-bidding-type').disabledForm();
        }
    })

    $('#field-detail-opOwner').on('selectUserCallback', function (event, user) {
        console.log(user.email)
        formDetail.email = user.email;
        $('#field-detail-email').find('input').val(user.email);
    })
});

sourcingRequisitionDetail.verify.addEvent('status', function () {
    var data = _data.formDetail;
    var formDetail = data.formDetail;
    var formStatus = $.toNumber(data.formStatus);
    var action = $.getUrlParams(window.location.href, 'action');
    // if (!sourcingRequisitionDetail.verify.isRequester() &&
    //     !sourcingRequisitionDetail.verify.isApprover() &&
    //     !sourcingRequisitionDetail.verify.isViewer()) {
    //     return $.alert(_enumMessage.forbidden, sourcingRequisitionDetail.form.exitForm);
    // }
    $('#form-detail').disabledForm();
    switch (formStatus) {
        case _enumFormStatus.submitted:
            if (action == 'edit') {
                // $('#block-utb-field').removeClass('dn');
                // $('#block-utb-field').enabledForm();
                $('#field-utb-spec-category').enabledForm();
                $('#block-operation-information').enabledForm();
                $('#block-operation-information').find('.btn[exit], .btn[submit]').removeClass('dn');
            } else {
                $('#block-operation-information').enabledForm();
                $('#block-operation-information').find('.btn[exit], .btn[edit], .btn[kickoff]').removeClass('dn');
            }
            $('#field-utb-specItemList thead th:last').addClass('dn');
            $('#field-utb-specItemList tbody tr').find('td:last').addClass('dn');
            break;
        case _enumFormStatus.approved1:
            $('#block-utb-field').removeClass('dn');
            $('#block-utb-field').enabledForm();
            $('#block-operation-information').enabledForm();
            $('#field-utb-bidding-type').disabledForm();
            $('#block-operation-information').find('.btn[exit], .btn[complete]').removeClass('dn');
            $('#field-utb-specItemList thead th:last').addClass('dn');
            $('#field-utb-specItemList tbody tr').find('td:last').addClass('dn');
            break;
        case _enumFormStatus.saved:
            $('#form-detail').enabledForm();
            $('#block-operation-information').find('.btn[exit], .btn[save], .btn[submit]').removeClass('dn');
            $('#field-utb-specItemList thead th:last').removeClass('dn');
            $('#field-utb-specItemList tbody tr').find('td:last').removeClass('dn');
            break;
        case _enumFormStatus.completed:
            $('#block-utb-field').removeClass('dn');
            $('#block-summary').removeClass('dn');
            $('#block-operation-information').enabledForm();
            $('#block-operation-information').find('.btn[exit]').removeClass('dn');
            $('#field-utb-specItemList thead th:last').addClass('dn');
            $('#field-utb-specItemList tbody tr').find('td:last').addClass('dn');
            break;
        default:
            $('#form-detail').enabledForm();
            $('#block-operation-information').find('.btn[exit], .btn[save], .btn[submit]').removeClass('dn');
            $('#field-utb-specItemList thead th:last').removeClass('dn');
            $('#field-utb-specItemList tbody tr').find('td:last').removeClass('dn');
            break;
    }

})

//save module
sourcingRequisitionDetail.save.addEvent('formDetail', function () {
    var formStatus = _data.formDetail.formStatus;
    var formDetail = $.extend({}, $('#form-detail').data('detail'));
    formDetail.costCenter = formDetail.costCenter ? [formDetail.costCenter] : [];
    formDetail.legalEntity = formDetail.legalEntity ? [formDetail.legalEntity] : [];
    // formDetail.approvalStep1Approver = formDetail.atsApprover.employeeId;
    // approvalStep1Role
    formDetail.approvalStep1Approver = 'C217353';
    formDetail.approvalStep2Approver = 'C217353';
    formDetail.approvalStep3Approver = 'C217353';
    formDetail.specificationInformationList = sourcingRequisitionDetail.save.specInformation.specificationInformationList();
    formDetail.complianceAudit = $.toSringReturnBoolean('是', '否', formDetail.complianceAudit);
    formDetail.qualityAudit = $.toSringReturnBoolean('是', '否', formDetail.qualityAudit);
    return formDetail;
});
sourcingRequisitionDetail.save.specInformation.addEvent('specificationInformationList', function () {
    var data = $.extend({}, $('#form-detail').data('detail'));
    var specificationInformationList = [];
    var specificationInformationListDom = $('#field-utb-specItemList tr[data]');
    for (var i = 0; i < specificationInformationListDom.length; i++)
        specificationInformationList.push(specificationInformationListDom.eq(i).data('item'));
    return specificationInformationList;
});

//verify module
sourcingRequisitionDetail.verify.addEvent('submitForm', function () {
    var judge = true;
    var data = sourcingRequisitionDetail.save.formDetail();
    $('#form-detail *[form]').findFormUnit().verifyClean();
    _message = '\n' + _enumMessage.operationError;
    console.log(data.legalEntity)
    if (!(data.legalEntity instanceof Array) || !data.legalEntity.length) {
        judge = false;
        $('#field-detail-legalEntity').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.legalEntityRequired);
    }
    if ($.isEmpty(data.activityName)) {
        judge = false;
        $('#field-detail-activeName').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.activeNameRequired);
    }
    if ($.isEmpty(data.department)) {
        judge = false;
        $('#field-detail-department').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.departmentRequired);
    }
    if (!(data.costCenter instanceof Array) || !data.costCenter.length) {
        judge = false;
        $('#field-detail-costCenter').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.costCenterRequired);
    }
    if ($.isEmpty(data.atsApprover) || $('#field-detail-atsApprover').findFormUnit().val() != (data.atsApprover.employeeId + ' / ' + data.atsApprover.chineseName)) {
        judge = false;
        $('#field-detail-atsApprover').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.atsApproverRequired);
    }
    if ($.isEmpty(data.opOwner) || $('#field-detail-opOwner').findFormUnit().val() != (data.opOwner.employeeId + ' / ' + data.opOwner.chineseName)) {
        judge = false;
        $('#field-detail-opOwner').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.opOwner1Required);
    }
    if (data.opOwner.employeeId == data.atsApprover.employeeId) {
        judge = false;
        $('#field-detail-opOwner').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.opOwner2Required);
    }
    if ($.isEmpty(data.email)) {
        judge = false;
        $('#field-detail-email').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.emailRequired);
    }
    // if (!(data.Specifications instanceof Array) || !data.Specifications.length) {
    //     judge = false;
    //     // $('#field-detail-legalEntity').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.legalEntityRequired);
    // }
    if ($.isEmpty(data.utbSpecCategory)) {
        judge = false;
        $('#field-utb-spec-category').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.CategoryRequired);
    }
    if ($.isEmpty(data.complianceAudit)) {
        judge = false;
        $('#field-statement-compliance').verifyIconErrorAndHelp(sourcingRequisitionDetail.message.specInformation.complianceRequired);
    }
    if ($.isEmpty(data.qualityAudit)) {
        judge = false;
        $('#field-statement-quality').verifyIconErrorAndHelp(sourcingRequisitionDetail.message.specInformation.qualityRequired);
    }
    // if ($.isEmpty(data.qualityAudit)) {
    //     judge = false;
    //     $('#field-statement-quality').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.legalEntityRequired);
    // }
    if (!judge) $.alert(_message);
    return judge;
});

//verify module
sourcingRequisitionDetail.verify.addEvent('kickoffForm', function () {
    var judge = true;
    var data = sourcingRequisitionDetail.save.formDetail();
    $('#form-detail *[form]').findFormUnit().verifyClean();
    _message = '\n' + _enumMessage.operationError;
    if ($.isEmpty(data.utbSpecCategory)) {
        judge = false;
        $('#field-utb-spec-category').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.CategoryRequired);
    }
    if (!judge) $.alert(_message);
    return judge;
});

sourcingRequisitionDetail.verify.addEvent('completeForm', function () {
    var judge = true;
    var data = sourcingRequisitionDetail.save.formDetail();
    $('#form-detail *[form]').findFormUnit().verifyClean();
    _message = '\n' + _enumMessage.operationError;
    if ($.isEmpty(data.utbContractAmount)) {
        judge = false;
        $('#field-utb-contract-amount').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.utbContractAmountRequired);
    }
    if ($.isEmpty(data.utbBidding)) {
        judge = false;
        $('#field-utb-bidding').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.utbBiddingRequired);
    }
    if (data.utbBidding == 'true' && $.isEmpty(data.utbBiddingType)) {
        judge = false;
        $('#field-utb-bidding').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.utbBiddingRequired);
    }
    if ($.isEmpty(data.utbCostAvoidance)) {
        judge = false;
        $('#field-utb-cost-avoidance').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.utbCostAvoidanceRequired);
    }
    if ($.isEmpty(data.utbCostSaving)) {
        judge = false;
        $('#field-utb-cost-saving').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.utbCostSavingRequired);
    }
    if ($.isEmpty(data.utbLateInvolvment)) {
        judge = false;
        $('#field-utb-late-involvment').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.utbLateInvolvmentRequired);
    }

    if ($.isEmpty(data.utbLowestPriceSelected)) {
        judge = false;
        $('#field-utb-lowest-price-selected').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.utbLowestPriceSelectedRequired);
    }
    if ($.isEmpty(data.utbProcurementType)) {
        judge = false;
        $('#field-utb-procurement-type').verifyErrorAndHelp(sourcingRequisitionDetail.message.specInformation.utbProcurementTypeRequired);
    }
    if (!judge) $.alert(_message);
    return judge;
});
sourcingRequisitionDetail.verify.specInformation.addEvent('specificationInformationList', function () {
    var judge = true;
    var specificationInformationListDom = $('#field-utb-specItemList tr[data]');
    for (var i = 0; i < specificationInformationListDom.length; i++) {
        var specificationInformationItemDom = specificationInformationListDom.eq(i);
        var utbSpecDescDom = specificationInformationItemDom.find('.form-control').eq(0);
        var utbSpecDateDom = specificationInformationItemDom.find('.form-control').eq(3);
        var data = specificationInformationItemDom.data('item');
        if ($.isEmpty(data.utbSpecDesc)) {
            judge = false;
            utbSpecDescDom.verifyError().verifyHelp(sourcingRequisitionDetail.message.specInformation.utbSpecDescRequired);
        }
        if ($.isEmpty(data.utbSpecDate)) {
            judge = false;
            utbSpecDateDom.verifyError().verifyHelp(sourcingRequisitionDetail.message.specInformation.utbSpecDateRequired);
        }
    }
    return judge;
});

//message module
sourcingRequisitionDetail.message.specInformation.addConfig('legalEntityRequired', '业务实体必填');
sourcingRequisitionDetail.message.specInformation.addConfig('activeNameRequired', '项目名称必填');
sourcingRequisitionDetail.message.specInformation.addConfig('departmentRequired', '部门必填');
sourcingRequisitionDetail.message.specInformation.addConfig('costCenterRequired', '成本中心必填');
sourcingRequisitionDetail.message.specInformation.addConfig('atsApproverRequired', '成本中心审批人必填');
sourcingRequisitionDetail.message.specInformation.addConfig('opOwner1Required', ' 业务申请人必填');
sourcingRequisitionDetail.message.specInformation.addConfig('opOwner2Required', '业务申请人和成本中心审批人重复');
sourcingRequisitionDetail.message.specInformation.addConfig('emailRequired', 'Email未填或格式错误');
sourcingRequisitionDetail.message.specInformation.addConfig('CategoryRequired', '采购品类必填');
sourcingRequisitionDetail.message.specInformation.addConfig('complianceRequired', '合规审核必填');
sourcingRequisitionDetail.message.specInformation.addConfig('qualityRequired', '质量审核必填');

sourcingRequisitionDetail.message.specInformation.addConfig('utbContractAmountRequired', '合同金额必填');
sourcingRequisitionDetail.message.specInformation.addConfig('utbBiddingRequired', '比价必填');
sourcingRequisitionDetail.message.specInformation.addConfig('utbCostAvoidanceRequired', '质量审核必填');
sourcingRequisitionDetail.message.specInformation.addConfig('utbCostSavingRequired', '节约成本必填');
sourcingRequisitionDetail.message.specInformation.addConfig('utbLowestPriceSelectedRequired', '选择最低价必填');
sourcingRequisitionDetail.message.specInformation.addConfig('utbLateInvolvmentRequired', '滞后介入必填');
sourcingRequisitionDetail.message.specInformation.addConfig('utbProcurementTypeRequired', '采购类型必填');

sourcingRequisitionDetail.message.specInformation.addConfig('specificationInformationListLimit', '最多10个');
sourcingRequisitionDetail.message.specInformation.addConfig('utbSpecDescRequired', '业务简述必填');
sourcingRequisitionDetail.message.specInformation.addConfig('utbSpecDateRequired', '业务开展时间必填');
